package com.fr.data.impl;

import com.fr.base.ArrayUtils;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.data.AbstractDict;
import com.fr.data.Dictionary;
import com.fr.data.Dictionary.MV;
import com.fr.data.core.DataUtils;
import com.fr.report.script.Calculator;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class CustomDictionary extends AbstractDict
{
  protected Object[] keys;
  protected Object[] values;

  public CustomDictionary()
  {
    this.keys = new Object[0];
    this.values = new Object[0];
  }

  public CustomDictionary(Object[] paramArrayOfObject1, Object[] paramArrayOfObject2)
  {
    setKV(paramArrayOfObject1, paramArrayOfObject2);
  }

  public void setKV(Object[] paramArrayOfObject1, Object[] paramArrayOfObject2)
  {
    if (ArrayUtils.isSameLength(paramArrayOfObject1, paramArrayOfObject2))
    {
      this.keys = paramArrayOfObject1;
      this.values = paramArrayOfObject2;
    }
  }

  public int size()
  {
    return this.keys.length;
  }

  public Object[] keys()
  {
    return this.keys;
  }

  public Object[] values()
  {
    return this.values;
  }

  public Object getKey(int paramInt)
  {
    return this.keys[paramInt];
  }

  public Object getValue(int paramInt)
  {
    return this.values[paramInt];
  }

  public Object get(Object paramObject, Calculator paramCalculator)
  {
    int i = 0;
    int j = size();
    while (i < j)
    {
      if (ComparatorUtils.equals(this.keys[i], paramObject))
        return this.values[i];
      ++i;
    }
    return null;
  }

  public boolean equals(Object paramObject)
  {
    return ((paramObject instanceof CustomDictionary) && (super.equals(paramObject)) && (ComparatorUtils.equals(((CustomDictionary)paramObject).keys, this.keys)) && (ComparatorUtils.equals(((CustomDictionary)paramObject).values, this.values)));
  }

  public Iterator entrys(Calculator paramCalculator)
  {
    return new EntryIterator(this, null);
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str = paramXMLableReader.getTagName();
      if (("CustomDictAttr".equals(str)) || ("CustomMapAttr".equals(str)))
      {
        ArrayList localArrayList1 = new ArrayList();
        ArrayList localArrayList2 = new ArrayList();
        paramXMLableReader.readXMLObject(new XMLReadable(this, localArrayList1, localArrayList2)
        {
          private final List val$kl;
          private final List val$vl;
          private final CustomDictionary this$0;

          public void readXML()
          {
            if (paramXMLableReader.isChildNode())
            {
              String str = paramXMLableReader.getTagName();
              if (("Dict".equals(str)) || ("CustomMap".equals(str)))
              {
                this.val$kl.add(DataUtils.readDictObject(paramXMLableReader.getAttr("key")));
                this.val$vl.add(DataUtils.readDictObject(paramXMLableReader.getAttr("value")));
              }
            }
          }
        });
        this.keys = localArrayList1.toArray();
        this.values = localArrayList2.toArray();
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("CustomDictAttr");
    int i = 0;
    int j = size();
    while (i < j)
    {
      paramXMLPrintWriter.startTAG("Dict").attr("key", DataUtils.writeDictObject(this.keys[i])).attr("value", DataUtils.writeDictObject(this.values[i])).end();
      ++i;
    }
    paramXMLPrintWriter.end();
  }

  public String toString()
  {
    return "CustomDict[DictSize:" + size() + "]";
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    return super.clone();
  }

  public static CustomDictionary customify(Dictionary paramDictionary)
  {
    ArrayList localArrayList1 = new ArrayList();
    ArrayList localArrayList2 = new ArrayList();
    if (paramDictionary != null)
    {
      Iterator localIterator = paramDictionary.entrys(null);
      while (localIterator.hasNext())
      {
        Dictionary.MV localMV = (Dictionary.MV)localIterator.next();
        localArrayList1.add(localMV.getModel());
        localArrayList2.add(localMV.getView());
      }
    }
    return new CustomDictionary(localArrayList1.toArray(), localArrayList2.toArray());
  }

  private class EntryIterator
    implements Iterator
  {
    private int next;
    private final CustomDictionary this$0;

    private EntryIterator()
    {
      this.this$0 = paramCustomDictionary;
      this.next = 0;
    }

    public boolean hasNext()
    {
      return (this.next < this.this$0.size());
    }

    public Object next()
    {
      Dictionary.MV localMV = new Dictionary.MV(this.this$0.keys[this.next], this.this$0.values[this.next]);
      this.next += 1;
      return localMV;
    }

    public void remove()
    {
    }

    EntryIterator(, CustomDictionary.1 param1)
    {
      this(paramCustomDictionary);
    }
  }
}